package cn.jbit.controller;

import cn.jbit.entitys.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张在成
 */
@RestController
public class EsUserController {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    //@Autowired
    //private EsUserDao esUserDao;

    @RequestMapping(value = "/create_mapping",method = RequestMethod.GET)
    public  Object  createEsUserIndexmapping(){
        //User user=new User();
        Document index=elasticsearchRestTemplate.indexOps(User.class).createMapping(User.class);
        boolean flag=elasticsearchRestTemplate.indexOps(User.class).putMapping(User.class);
        System.out.println("获取响应值："+index);
        System.out.println("获取到的索引结果是；"+flag);
        return  index;

    }

    @RequestMapping(value = "/create_user",method = RequestMethod.GET)
    public  Object  createEsUserIndex(){
        //User user=new User();
        boolean index=elasticsearchRestTemplate.indexOps(User.class).create();
        System.out.println("获取索引的是否创建成功："+index);
        return  index;
    }


}
